package 异常;

import java.io.IOException;

public class Person {
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws IllegalAgeException {
        if (age<0||age>100){
            //throw 跟return一样，遇到后会结束方法
            //RuntimeException类型的异常属于bug级别异常，发现后可以用逻辑去解决，所以不用抛异常
           // throw new RuntimeException("年龄超出了0-100");//该方法可以不写throw
            throw new IllegalAgeException("年龄超出了0-100");
        }
        this.age = age;
    }
}
